package com.dynamixsoftware.printershare.smb;

import com.dynamixsoftware.printershare.smb.util.Dumper;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.TimeZone;

abstract class ServerMessageBlock
  extends Response
  implements Request, SmbConstants
{
  static final byte SMB_COM_CHECK_DIRECTORY = 16;
  static final byte SMB_COM_CLOSE = 4;
  static final byte SMB_COM_CLOSE_PRINT_FILE = -62;
  static final byte SMB_COM_CREATE_DIRECTORY = 0;
  static final byte SMB_COM_DELETE = 6;
  static final byte SMB_COM_DELETE_DIRECTORY = 1;
  private static final byte SMB_COM_ECHO = 43;
  static final byte SMB_COM_FIND_CLOSE2 = 52;
  static final byte SMB_COM_LOGOFF_ANDX = 116;
  private static final byte SMB_COM_MOVE = 42;
  static final byte SMB_COM_NEGOTIATE = 114;
  static final byte SMB_COM_NT_CREATE_ANDX = -94;
  static final byte SMB_COM_NT_TRANSACT = -96;
  static final byte SMB_COM_NT_TRANSACT_SECONDARY = -95;
  static final byte SMB_COM_OPEN_ANDX = 45;
  static final byte SMB_COM_OPEN_PRINT_FILE = -64;
  static final byte SMB_COM_QUERY_INFORMATION = 8;
  static final byte SMB_COM_READ_ANDX = 46;
  static final byte SMB_COM_RENAME = 7;
  static final byte SMB_COM_SESSION_SETUP_ANDX = 115;
  static final byte SMB_COM_TRANSACTION = 37;
  static final byte SMB_COM_TRANSACTION2 = 50;
  static final byte SMB_COM_TRANSACTION_SECONDARY = 38;
  static final byte SMB_COM_TREE_CONNECT_ANDX = 117;
  static final byte SMB_COM_TREE_DISCONNECT = 113;
  static final byte SMB_COM_WRITE = 11;
  static final byte SMB_COM_WRITE_ANDX = 47;
  static final byte SMB_COM_WRITE_PRINT_FILE = -63;
  private static final byte[] header = { -1, 83, 77, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  NtlmPasswordAuthentication auth = null;
  int batchLevel = 0;
  int byteCount;
  byte command;
  SigningDigest digest = null;
  int errorCode;
  boolean extendedSecurity;
  byte flags = 24;
  int flags2;
  int headerStart;
  int length;
  int mid;
  String path;
  int pid = PID;
  boolean received;
  ServerMessageBlock response;
  int signSeq;
  int tid;
  int uid;
  boolean useUnicode;
  boolean verifyFailed;
  int wordCount;
  
  static int readInt2(byte[] paramArrayOfByte, int paramInt)
  {
    return (0xFF & paramArrayOfByte[paramInt]) + ((0xFF & paramArrayOfByte[(paramInt + 1)]) << 8);
  }
  
  static int readInt4(byte[] paramArrayOfByte, int paramInt)
  {
    return (0xFF & paramArrayOfByte[paramInt]) + ((0xFF & paramArrayOfByte[(paramInt + 1)]) << 8) + ((0xFF & paramArrayOfByte[(paramInt + 2)]) << 16) + ((0xFF & paramArrayOfByte[(paramInt + 3)]) << 24);
  }
  
  static long readInt8(byte[] paramArrayOfByte, int paramInt)
  {
    return (0xFFFFFFFF & readInt4(paramArrayOfByte, paramInt)) + (readInt4(paramArrayOfByte, paramInt + 4) << 32);
  }
  
  static long readTime(byte[] paramArrayOfByte, int paramInt)
  {
    int i = readInt4(paramArrayOfByte, paramInt);
    return (readInt4(paramArrayOfByte, paramInt + 4) << 32 | 0xFFFFFFFF & i) / 10000L - 11644473600000L;
  }
  
  static long readUTime(byte[] paramArrayOfByte, int paramInt)
  {
    return 1000L * readInt4(paramArrayOfByte, paramInt);
  }
  
  static void writeInt2(long paramLong, byte[] paramArrayOfByte, int paramInt)
  {
    paramArrayOfByte[paramInt] = ((byte)(int)paramLong);
    paramArrayOfByte[(paramInt + 1)] = ((byte)(int)(paramLong >> 8));
  }
  
  static void writeInt4(long paramLong, byte[] paramArrayOfByte, int paramInt)
  {
    paramArrayOfByte[paramInt] = ((byte)(int)paramLong);
    int i = paramInt + 1;
    long l1 = paramLong >> 8;
    paramArrayOfByte[i] = ((byte)(int)l1);
    int j = i + 1;
    long l2 = l1 >> 8;
    paramArrayOfByte[j] = ((byte)(int)l2);
    paramArrayOfByte[(j + 1)] = ((byte)(int)(l2 >> 8));
  }
  
  static void writeInt8(long paramLong, byte[] paramArrayOfByte, int paramInt)
  {
    paramArrayOfByte[paramInt] = ((byte)(int)paramLong);
    int i = paramInt + 1;
    long l1 = paramLong >> 8;
    paramArrayOfByte[i] = ((byte)(int)l1);
    int j = i + 1;
    long l2 = l1 >> 8;
    paramArrayOfByte[j] = ((byte)(int)l2);
    int k = j + 1;
    long l3 = l2 >> 8;
    paramArrayOfByte[k] = ((byte)(int)l3);
    int m = k + 1;
    long l4 = l3 >> 8;
    paramArrayOfByte[m] = ((byte)(int)l4);
    int n = m + 1;
    long l5 = l4 >> 8;
    paramArrayOfByte[n] = ((byte)(int)l5);
    int i1 = n + 1;
    long l6 = l5 >> 8;
    paramArrayOfByte[i1] = ((byte)(int)l6);
    paramArrayOfByte[(i1 + 1)] = ((byte)(int)(l6 >> 8));
  }
  
  static void writeUTime(long paramLong, byte[] paramArrayOfByte, int paramInt)
  {
    if ((paramLong == 0L) || (paramLong == -1L))
    {
      writeInt4(-1L, paramArrayOfByte, paramInt);
      return;
    }
    synchronized (TZ)
    {
      if (TZ.inDaylightTime(new Date())) {
        if (!TZ.inDaylightTime(new Date(paramLong))) {}
      }
      while (!TZ.inDaylightTime(new Date(paramLong))) {
        for (;;)
        {
          writeInt4((int)(paramLong / 1000L), paramArrayOfByte, paramInt);
          return;
          paramLong -= 3600000L;
        }
      }
      paramLong += 3600000L;
    }
  }
  
  int decode(byte[] paramArrayOfByte, int paramInt)
  {
    this.headerStart = paramInt;
    int i = paramInt + readHeaderWireFormat(paramArrayOfByte, paramInt);
    int j = i + 1;
    this.wordCount = paramArrayOfByte[i];
    if (this.wordCount != 0) {
      readParameterWordsWireFormat(paramArrayOfByte, j);
    }
    for (int k = j + 2 * this.wordCount;; k = j)
    {
      this.byteCount = readInt2(paramArrayOfByte, k);
      int m = k + 2;
      if (this.byteCount != 0)
      {
        readBytesWireFormat(paramArrayOfByte, m);
        m += this.byteCount;
      }
      this.length = (m - paramInt);
      return this.length;
    }
  }
  
  int encode(byte[] paramArrayOfByte, int paramInt)
  {
    this.headerStart = paramInt;
    int i = paramInt + writeHeaderWireFormat(paramArrayOfByte, paramInt);
    this.wordCount = writeParameterWordsWireFormat(paramArrayOfByte, i + 1);
    int j = i + 1;
    paramArrayOfByte[i] = ((byte)(0xFF & this.wordCount / 2));
    int k = j + this.wordCount;
    this.wordCount /= 2;
    this.byteCount = writeBytesWireFormat(paramArrayOfByte, k + 2);
    int m = k + 1;
    paramArrayOfByte[k] = ((byte)(0xFF & this.byteCount));
    int n = m + 1;
    paramArrayOfByte[m] = ((byte)(0xFF & this.byteCount >> 8));
    this.length = (n + this.byteCount - paramInt);
    if (this.digest != null) {
      this.digest.sign(paramArrayOfByte, this.headerStart, this.length, this, this.response);
    }
    return this.length;
  }
  
  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof ServerMessageBlock)) && (((ServerMessageBlock)paramObject).mid == this.mid);
  }
  
  public int hashCode()
  {
    return this.mid;
  }
  
  boolean isResponse()
  {
    return (0x80 & this.flags) == 128;
  }
  
  abstract int readBytesWireFormat(byte[] paramArrayOfByte, int paramInt);
  
  int readHeaderWireFormat(byte[] paramArrayOfByte, int paramInt)
  {
    this.command = paramArrayOfByte[(paramInt + 4)];
    this.errorCode = readInt4(paramArrayOfByte, paramInt + 5);
    this.flags = paramArrayOfByte[(paramInt + 9)];
    this.flags2 = readInt2(paramArrayOfByte, 1 + (paramInt + 9));
    this.tid = readInt2(paramArrayOfByte, paramInt + 24);
    this.pid = readInt2(paramArrayOfByte, 2 + (paramInt + 24));
    this.uid = readInt2(paramArrayOfByte, 4 + (paramInt + 24));
    this.mid = readInt2(paramArrayOfByte, 6 + (paramInt + 24));
    return 32;
  }
  
  abstract int readParameterWordsWireFormat(byte[] paramArrayOfByte, int paramInt);
  
  String readString(byte[] paramArrayOfByte, int paramInt)
  {
    return readString(paramArrayOfByte, paramInt, 256, this.useUnicode);
  }
  
  String readString(byte[] paramArrayOfByte, int paramInt1, int paramInt2, int paramInt3, boolean paramBoolean)
  {
    if (paramBoolean) {}
    for (;;)
    {
      try
      {
        if ((paramInt1 - this.headerStart) % 2 != 0)
        {
          paramInt1++;
          continue;
          if ((1 + (paramInt1 + j) >= paramInt2) || ((paramArrayOfByte[(paramInt1 + j)] == 0) && (paramArrayOfByte[(1 + (paramInt1 + j))] == 0))) {
            return new String(paramArrayOfByte, paramInt1, j, "UTF-16LE");
          }
          if (j <= paramInt3) {
            break label144;
          }
          throw new RuntimeException("zero termination not found");
          if ((paramInt1 >= paramInt2) || (paramArrayOfByte[(paramInt1 + i)] == 0)) {
            return new String(paramArrayOfByte, paramInt1, i, "ISO-8859-1");
          }
          if (i > paramInt3) {
            throw new RuntimeException("zero termination not found");
          }
          i++;
          continue;
        }
        int j = 0;
        continue;
        j += 2;
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        return null;
      }
      label144:
      continue;
      int i = 0;
    }
  }
  
  String readString(byte[] paramArrayOfByte, int paramInt1, int paramInt2, boolean paramBoolean)
  {
    int i = 0;
    if (paramBoolean) {}
    for (;;)
    {
      try
      {
        int j = (paramInt1 - this.headerStart) % 2;
        int k = 0;
        if (j != 0) {
          paramInt1++;
        }
        if ((paramArrayOfByte[(paramInt1 + k)] != 0) || (paramArrayOfByte[(1 + (paramInt1 + k))] != 0))
        {
          k += 2;
          if (k <= paramInt2) {
            continue;
          }
          throw new RuntimeException("zero termination not found");
        }
        return new String(paramArrayOfByte, paramInt1, k, "UTF-16LE");
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException) {}
      if (paramArrayOfByte[(paramInt1 + i)] != 0)
      {
        i++;
        if (i > paramInt2) {
          throw new RuntimeException("zero termination not found");
        }
      }
      else
      {
        String str = new String(paramArrayOfByte, paramInt1, i, "ISO-8859-1");
        return str;
      }
    }
    return null;
  }
  
  int readStringLength(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
  {
    int j;
    for (int i = 0;; i = j) {
      if (paramArrayOfByte[(paramInt1 + i)] != 0)
      {
        j = i + 1;
        if (i > paramInt2) {
          throw new RuntimeException("zero termination not found: " + this);
        }
      }
      else
      {
        return i;
      }
    }
  }
  
  void reset()
  {
    this.flags = 24;
    this.flags2 = 0;
    this.errorCode = 0;
    this.received = false;
    this.digest = null;
  }
  
  int stringWireLength(String paramString, int paramInt)
  {
    int i = 1 + paramString.length();
    if (this.useUnicode)
    {
      i = 2 + 2 * paramString.length();
      if (paramInt % 2 != 0) {
        i++;
      }
    }
    return i;
  }
  
  public String toString()
  {
    String str1;
    switch (this.command)
    {
    default: 
      str1 = "UNKNOWN";
      if (this.errorCode != 0) {
        break;
      }
    }
    for (String str2 = "0";; str2 = SmbException.getMessageByCode(this.errorCode))
    {
      return new String("command=" + str1 + ",received=" + this.received + ",errorCode=" + str2 + ",flags=0x" + Dumper.toHexString(0xFF & this.flags, 4) + ",flags2=0x" + Dumper.toHexString(this.flags2, 4) + ",signSeq=" + this.signSeq + ",tid=" + this.tid + ",pid=" + this.pid + ",uid=" + this.uid + ",mid=" + this.mid + ",wordCount=" + this.wordCount + ",byteCount=" + this.byteCount);
      str1 = "SMB_COM_NEGOTIATE";
      break;
      str1 = "SMB_COM_SESSION_SETUP_ANDX";
      break;
      str1 = "SMB_COM_TREE_CONNECT_ANDX";
      break;
      str1 = "SMB_COM_QUERY_INFORMATION";
      break;
      str1 = "SMB_COM_CHECK_DIRECTORY";
      break;
      str1 = "SMB_COM_TRANSACTION";
      break;
      str1 = "SMB_COM_TRANSACTION2";
      break;
      str1 = "SMB_COM_TRANSACTION_SECONDARY";
      break;
      str1 = "SMB_COM_FIND_CLOSE2";
      break;
      str1 = "SMB_COM_TREE_DISCONNECT";
      break;
      str1 = "SMB_COM_LOGOFF_ANDX";
      break;
      str1 = "SMB_COM_ECHO";
      break;
      str1 = "SMB_COM_MOVE";
      break;
      str1 = "SMB_COM_RENAME";
      break;
      str1 = "SMB_COM_DELETE";
      break;
      str1 = "SMB_COM_DELETE_DIRECTORY";
      break;
      str1 = "SMB_COM_NT_CREATE_ANDX";
      break;
      str1 = "SMB_COM_OPEN_ANDX";
      break;
      str1 = "SMB_COM_READ_ANDX";
      break;
      str1 = "SMB_COM_CLOSE";
      break;
      str1 = "SMB_COM_WRITE_ANDX";
      break;
      str1 = "SMB_COM_CREATE_DIRECTORY";
      break;
      str1 = "SMB_COM_NT_TRANSACT";
      break;
      str1 = "SMB_COM_NT_TRANSACT_SECONDARY";
      break;
    }
  }
  
  abstract int writeBytesWireFormat(byte[] paramArrayOfByte, int paramInt);
  
  int writeHeaderWireFormat(byte[] paramArrayOfByte, int paramInt)
  {
    System.arraycopy(header, 0, paramArrayOfByte, paramInt, header.length);
    paramArrayOfByte[(paramInt + 4)] = this.command;
    paramArrayOfByte[(paramInt + 9)] = this.flags;
    writeInt2(this.flags2, paramArrayOfByte, 1 + (paramInt + 9));
    int i = paramInt + 24;
    writeInt2(this.tid, paramArrayOfByte, i);
    writeInt2(this.pid, paramArrayOfByte, i + 2);
    writeInt2(this.uid, paramArrayOfByte, i + 4);
    writeInt2(this.mid, paramArrayOfByte, i + 6);
    return 32;
  }
  
  abstract int writeParameterWordsWireFormat(byte[] paramArrayOfByte, int paramInt);
  
  int writeString(String paramString, byte[] paramArrayOfByte, int paramInt)
  {
    return writeString(paramString, paramArrayOfByte, paramInt, this.useUnicode);
  }
  
  int writeString(String paramString, byte[] paramArrayOfByte, int paramInt, boolean paramBoolean)
  {
    int i = paramInt;
    if (paramBoolean) {}
    int i1;
    int i2;
    try
    {
      int n = (paramInt - this.headerStart) % 2;
      if (n != 0) {
        m = paramInt + 1;
      }
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException1) {}
    try
    {
      paramArrayOfByte[paramInt] = 0;
      paramInt = m;
      System.arraycopy(paramString.getBytes("UTF-16LE"), 0, paramArrayOfByte, paramInt, 2 * paramString.length());
      i1 = paramString.length();
      i2 = paramInt + i1 * 2;
      m = i2 + 1;
      paramArrayOfByte[i2] = 0;
      paramInt = m + 1;
      paramArrayOfByte[m] = 0;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException2)
    {
      paramInt = m;
    }
    byte[] arrayOfByte = paramString.getBytes("ISO-8859-1");
    System.arraycopy(arrayOfByte, 0, paramArrayOfByte, paramInt, arrayOfByte.length);
    int j = arrayOfByte.length;
    int k = paramInt + j;
    int m = k + 1;
    paramArrayOfByte[k] = 0;
    paramInt = m;
    return paramInt - i;
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.smb.ServerMessageBlock
 * JD-Core Version:    0.7.0.1
 */